package com.net.shop.car.manager.ui.viewholder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.net.shop.car.manager.BaseActivity;
import com.net.shop.car.manager.R;
import com.net.shop.car.manager.api.model.Goods;

public class ServiceGoodsAdapter extends BaseAdapter {

	private BaseActivity activity;
	private List<Goods> goods;
	private OnGoodsAddedShopCarListener listener;
	private Map<Goods, Boolean> goodsInShop = new HashMap<Goods, Boolean>();
	private boolean isPay;
 
	public ServiceGoodsAdapter(List<Goods> goods, boolean isPay,BaseActivity activity,OnGoodsAddedShopCarListener listener) {
		this.activity = activity;
		this.goods = goods;
		this.listener = listener;
		this.isPay = isPay;
		for (Goods good : goods) {
			goodsInShop.put(good, false);
		}
	}

	@Override
	public int getCount() {
		return goods == null ? 0 : goods.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View curentView = convertView;
		final Goods good = goods.get(position);
		if (curentView == null) {
			curentView = activity.inflater.inflate(R.layout.item_service_layout, parent, false);
			curentView.setTag(new GoodViewHolder(curentView,listener,isPay));
		}
		GoodViewHolder goodViewHolder = (GoodViewHolder) curentView.getTag();
		goodViewHolder.setGood(good,goodsInShop.get(good));
		return curentView;
	}

}
